/**
 * This file is Copyright © 2008 Software Craftsmen Limited. All Rights Reserved.
 */
package com.softwarecraftsmen.functors;

import org.jetbrains.annotations.NotNull;

public final class WhileDo
{
	private static void whileDo(final @NotNull NullaryReturningFunctor<Boolean> test, final @NotNull NullaryFunctor loopBlock)
	{
		while (test.closure().isTrue())
		{
			loopBlock.closure();
		}
	}

	@NotNull
	public static ThenDo while$(final @NotNull NullaryReturningFunctor<Boolean> test)
	{
		return new ThenDo(test);
	}

	public static final class ThenDo
	{
		private final NullaryReturningFunctor<Boolean> test;

		private ThenDo(final @NotNull NullaryReturningFunctor<Boolean> test)
		{
			this.test = test;
		}

		public void do$(final @NotNull NullaryFunctor loopBlock)
		{
			whileDo(test, loopBlock);
		}
	}

	private WhileDo()
	{}
}